'; window.popUpWin.document.write(zhtm); window.popUpWin.document.close(); // Johnny Jackson 4/28/98 } //--> Inside AutoCAD 14 -- Ch 23 -- Creating Scripts and Slide Libraries


Inside AutoCAD 14

Previous chapterNext chapterContents



- 23 -

Creating Scripts and Slide Libraries

by Bill Burchard

The typical CAD technician seldom uses two useful AutoCAD features--script files and slide libraries. Most users consider these two features the realm of the "AutoCAD Guru." That is a shame, too, because they are fairly simple to learn and very useful for performing repetitive tasks.

A script file is simply a series of AutoCAD commands and responses to those commands, saved in an ASCII text file. The easiest way to create a script is to write the AutoCAD commands down on a piece of paper exactly as you enter them into an AutoCAD editing session. Then, use a basic text editor and type each command and its responses on a separate line. Save the file with a .SCR extension and voilá, you've created an AutoCAD script. Script files can easily execute many commands. For example, you can use script files to insert blocks, attach xrefs, draw objects, or plot drawings. Script files are the simplest form of writing programs for AutoCAD.

Slide libraries store a series of AutoCAD images. You can recall these images and automatically display them as a series of slides, creating a slide show. You also can recall them for display in image tile menus. Image tile menus provide a graphic way to show users what AutoCAD function will execute if they select a particular tile.

By using these two features, you can easily and quickly automate your work and increase your productivity.

This chapter discusses the following subjects:

Using Script Files

Through Release 13, one use for script files had been to implement batch plotting. Release 14's new Batch Plot Utility begins replacing the use of script files for straight-forward plotting situations. The new utility enables you to easily open a series of drawings, associate a PCP file with each, and then plot each drawing. You can use this routine to automatically plot hundreds of drawings unattended. However, the Batch Plot Utility does have some limitations when dealing with more complicated plotting situations. You can continue to use script files where the Batch Plot Utility falls short, as Chapter 20, "Productive Plotting," discusses.

There are additional uses for script files. You can easily automate repetitive tasks, just by writing simple script files. The remainder of this section discusses a few applications of script files.

Automating Your Drawing Environment

You can use script files to set up your working environment. You can load AutoLISP routines, insert blocks into the block table, load linetypes, and set text styles. You can automate all these functions using a single script file.


NOTE: I find using scripts to set my working environment useful when I'm temporarily working at another CAD technician's station. I simply place the files I need to use on a floppy disk, along with a script file that loads them. Then, when I need to load the files, I execute the script command from the floppy disk. The script will execute and load the appropriate files. Then I'm ready to begin work.

Using Script Files to Load AutoLISP Routines

You can use scripts to automatically load AutoLISP routines. If you have several LISP routines that you frequently use during a drawing editing session, you can create a single script file to load them automatically.

To load LISP routines from a script, you can simply duplicate the LOAD command's syntax in the script file. You also can insert the AutoLISP code directly in the script file. Both methods load the AutoLISP routines.


TIP: In the following exercise, I use the Notepad program, which comes with both Windows 95 and Windows NT. I use it because it automatically saves files as ASCII text files. You may use any other text editor you prefer, as long as it saves the files as ASCII text files.

In the following exercise, you open an existing drawing for editing. Then, you create a script file that automatically loads three AutoLISP routines. Finally, the AutoLISP routines are used to edit the drawing.

USING SCRIPTS TO LOAD AUTOLISP ROUTINES

1. Open the 23DWG01.DWG drawing file found on the accompanying CD.

2. From the Start button on the Windows Taskbar, choose Programs, Accessories, Notepad. This opens Notepad.

3. In Notepad, enter the following lines:

; Define break object at endpoint LISP routine
(defun C:BRE (/) (command "BREAK" pause "F" "ENDP" pause "@"))
; Define break object at intersection LISP routine
(defun C:BRI (/) (command "BREAK" pause "F" "INT" pause "@"))
; Load SBL LISP routine
(_.load "SBL.LSP")
; End script file


This file represents a script file. The lines of text enclosed with parentheses is AutoLISP code. When you finish entering the text, be sure it includes the semicolons, slashes, quotes, and parentheses as shown. Also, it's very important to press the Enter key after typing the last line of text. This places the cursor at the beginning of a new blank line just below the last line of text.

4. Save the file in the ACADR14\SAMPLE directory and name it LOADIT.SCR. You must use the .SCR extension in naming scripts because this is the only way that AutoCAD recognizes the file as a script file.


TIP: Including comments in your code is good programming practice because it helps clarify what your routine is doing each step of the way. In script files, you can enter a comment by preceding it with a semicolon. When AutoCAD encounters a semicolon in a script file, it ignores the text that follows it. Watch out, on the other hand, for blank spaces. Script files are very sensitive to blank spaces. A blank space in a script file represents pressing the Enter key. Too many blank spaces in script files represent the most common problem encountered with scripts that do not execute as expected.

5. At the Command: prompt, type SCRIPT and press the Enter key. The Select Script File dialog box opens.

6. From the ACADR14\SAMPLE directory, open the LOADIT.SCR script file you just created. When you open the file, AutoCAD runs the script file, which defines the BRE and BRI AutoLISP routines and loads the SBL routine. Figure 23.1 shows the AutoCAD Text Window, which displays the commands executed through the script file and AutoCAD's responses.

Figure 23.1 The script file loads the three AutoLISP routines.

Notice that after AutoCAD loads each routine, it prints C: followed by three letters. The three letters are the command name you type to execute the routine. AutoCAD indicates that it has successfully loaded an AutoLISP routine by printing the routine's command name.


Next, you execute the three routines to verify that they loaded properly:

7. At the Command: prompt, type BRE and press the Enter key. The BRE routine executes the BREAK command. It breaks the selected object at an endpoint with a single pick.

8. At the BREAK Select object: prompt, pick the top horizontal line at 1, as shown in figure 23.2.

Figure 23.2 The bubble pick points.

9. Next, at the Enter first point: ENDP of prompt, pick the vertical line at 2.

The BRE routine automatically uses the endpoint snap to break the horizontal line at the point where the vertical line intersects it. You can verify the line is broken by picking it (assuming noun/verb selection is enabled, only the half of the original line you pick will highlight).


Next, you will verify that the BRI routine is working properly.

10. At the Command: prompt, type BRI and press the Enter key.

The BRI routine also executes the BREAK command. However, it breaks the selected object at an intersection with a single pick.

11. At the BREAK Select object : prompt, pick the vertical line at 2.

12. Next, at the Enter first point: INT of prompt pick the intersection of the circle and the vertical line at 3.

The BRI routine automatically uses the intersection snap to break the vertical line at the point at which the circle intersects it. You can verify the line is broken by choosing it to highlight it.


Finally, you will verify that the SBL routine is working properly.

13. At the Command: prompt, type SBL and press the Enter key.

The SBL routine uses the SCALE command to resize selected blocks. It scales the blocks from their insertion point. In the current drawing, the rectangles are inserted blocks.

The SBL routine prompts for a scale factor, and uses the value you enter to scale the blocks.

14. Type 0.5 and press the Enter key.

15. Select the blocks using any standard selection method (including the ALL argument). The SBL routine filters out all objects, except INSERT objects, when it creates its selection set.

AutoCAD resizes all the selected blocks to half their original size. If you created the script file correctly, you should be able to successfully execute the three AutoLISP routines.

As stated earlier, if you created the script file in the previous exercise correctly, you were able to successfully execute the three AutoLISP routines. If any of the routines failed to work, however, simply look over the data you entered in the script file and make sure it is correct. When you write programs, it is common to have a problem or two when you first try to run it (these little problems are called bugs). If you cannot figure out why your script file will not work, check out the 23SCR01.SCR script file on the accompanying CD. It is the correct version of the LOADIT.SCR file you created.

Using Script Files to Insert Blocks

Just as the previous discussion demonstrated how to use script files to load frequently used AutoLISP routines, you can also use script files to quickly load blocks into the current drawing's block table. This makes them immediately available for insertion.


NOTE: Note that in some cases using script files to load blocks can add to the size (number of bytes) of the drawing file--especially if many of the blocks are not used in the current drawing. There are, however, times when this is desirable. They include when the blocks are not locatable via the AutoCAD search path (eliminated typing disk/directory syntax to locate the block), when you're working on another computer and your block library does not exist there (your library is now part of your drawing), and when your network is very slow.

Using script files to load blocks, however, gets a little tricky. That's because you have to use the INSERT command to insert the block. After you select the block's drawing file, AutoCAD expects you to pick the insertion point. If you are only loading the block definitions into the block table, you don't need to insert the block. So then, normally, you cancel the INSERT command when AutoCAD prompts for the insertion point. Unfortunately, script files do not provide a mechanism to cancel an AutoCAD command that is in progress.

You can, however, cancel the current command using a little bit of AutoLISP code. When AutoCAD encounters the code, it passes control from the script file to the AutoLISP code. The AutoLISP code then cancels the current command and passes control back to the script file. It is a simple technique to use, and it provides the capability to automatically load hundreds of blocks into a drawing's block table without having to actually insert each one.

The following exercise demonstrates how to load blocks into the current drawing's block table using a script file. First, you open a drawing that contains no objects, nor block definitions in the block table. Next, you create a script file to load two block definitions into the current drawing. Finally, you verify that the blocks were successfully loaded by viewing them.

USING SCRIPT FILES TO LOAD BLOCKS

1. Open the 23DWG02.DWG drawing file found on the accompanying CD.


Next, you create a new script file.

2. From the Start button on the Windows Taskbar, choose Programs, Accessories, Notepad.

3. In Notepad, enter the following lines:

; Insert block
_.insert
; Arrowhead block
23DWG02a
; Cancel insert command, resume script file
(command \e "RESUME")
; Insert block
_.insert
; Construction bubble block
23DWG02b
; Cancel insert command
(command \e)


The lines of text are the commands and AutoLISP code that will load the blocks into the block table without forcing you to actually insert the blocks into model space. The lines of text enclosed with parentheses are AutoLISP code. When you finish entering the text, be sure it includes the semicolons, slashes, quotes, and parentheses as shown. As noted previously, it's very important to press the Enter key after typing the last line of text. This places the cursor at the beginning of a new blank line just below the last line of text.


TIP: Notice that an underscore and a period precedes the INSERT command. The underscore indicates that the command name is in English. The period instructs AutoCAD to use the original definition of the command. Always use the period to ensure that you don't inadvertently use a redefined version of the command.

4. Save the file in the ACADR14\SAMPLE directory and name it BLOCKS.SCR.


Next, execute the script file and load the blocks.

5. At the Command: prompt, type SCRIPT and press the Enter key. The Select Script File dialog box opens.

6. From the ACADR14\SAMPLE directory, open the BLOCKS.SCR script file you just created.

AutoCAD runs the script file, which loads the 23DWG02a.DWG and 23DWG02b.DWG drawing files. Figure 23.3 shows the AutoCAD Text Window, which displays the commands executed through the script file and AutoCAD's responses.

Figure 23.3 The script file loads the blocks into the block table.

Notice that when AutoCAD loads each block, it does not pause for an insertion point. Instead, it cancels the INSERT command, and then resumes running the script file.


Next, you view the two block definitions to verify that they loaded properly into the block table.

7. From Insert, choose Block. The Insert dialog box opens.

8. Click on the Block button. The Defined Blocks dialog box opens and displays the two blocks you loaded with the script file, as shown in figure 23.4. This verifies that the two blocks have been loaded.

Once you verify the blocks loaded, click on the Cancel button to exit the Defined Blocks dialog box. Click on the Cancel button again to exit the Insert dialog box.

Figure 23.4 The script file successfully loaded the blocks.

The technique of loading blocks into the block table described in the preceding exercise is very convenient. This technique can also be used if you use template files (which you should) to set up a new drawing, and the template contains dozens of blocks. By using script files to load the blocks, you can automate the process of setting up your template files and increase your productivity.

Automating Commands

The capability to create simple programs in AutoCAD provides a way to automate repetitive tasks. In the previous two script files, you used scripts to load and execute AutoLISP routines. In this discussion, you will use very simple AutoLISP code to launch script files.

You can load AutoLISP commands in AutoCAD by directly entering the code at the Command: prompt. Although you wouldn't want to do that for lengthy routines, it works fine for very simple ones. Routines that consist of one line of code are good candidates to enter quickly at the Command: prompt.

The next exercise demonstrates how to execute a script file from a simple AutoLISP routine. You open a blank drawing that contains a block definition. Then, you use a predefined script file to create a new layer and insert the block. Finally, you execute the script file from a simple AutoLISP routine.

EXECUTING SCRIPT FILES FROM AUTOLISP

1. Open the 23DWG03.DWG drawing file found on the accompanying CD.

2. Enter the following text at the Command: prompt exactly as shown and then press the Enter key:

(defun C:TB (/) (command "SCRIPT" "23SCR03.SCR"))

AutoCAD prints C:TB after you enter the text to indicate that it has loaded the routine. The script file that the routine executes is as follows:

; Create new layer
_.layer
; Make new layer
make
; New layer name
title_block
; Exit layer command
; Insert block
_.insert
; Insert the block named title_block
title_block
; Insertion coordinates
7,5
; X scale
1
; Y scale
1
; Rotation
0
;Exit script file

3. At the Command: prompt, type TB and press the Enter key.

The AutoLISP code executes the script file 23SCR03.SCR. The script file then creates the layer TITLE_BLOCK and makes it current. Finally, it inserts the block, as shown in figure 23.5. You have successfully executed a script file with a simple AutoLISP routine.

Figure 23.5 The script file is started by the AutoLISP command.

Another situation in which you use AutoLISP to execute script files is when you want to quickly toggle multiple layers on and off. By creating two script files, one that turns layers on and another that turns them off, you can easily modify your working environment.

The next exercise demonstrates how to create two simple AutoLISP routines that execute script files to toggle layers on and off.

TURNING LAYERS ON AND OFF WITH SCRIPT FILES

1. Open the 23DWG04.DWG drawing file found on the accompanying CD. The drawing contains several layers that you will toggle on and off with script files. The script files have already been created. 23SCR04a.SCR turns layers off and 23SCR04b.SCR turns layers on.


Next, you enter the AutoLISP code that executes the script files.

2. At the Command: prompt, enter the following line of code and then press the Enter key:

(defun C:LOF (/) (command "SCRIPT" "23SCR04a.SCR"))

AutoCAD responds by printing C:LOF. Typing LOF at the AutoCAD Command: prompt turns off the layers listed in the script file.

3. At the Command: prompt, enter the following line of code and then press the Enter key:

Command: (defun C:LON (/) (command "SCRIPT" "23SCR04b.SCR"))

AutoCAD responds by printing C:LON. By typing LON at the AutoCAD Command: prompt, you turn on the layers listed in the script file.

The script file that turns on the layers contains the following code:

; Turn on layers
_.layer
; Layers on
on
; Layers to turn on
buildings,contour*
; Exit layer command
; Exit script file

As you can see, the script file is very simple. It just turns on three layers. The script indicates one of the layers by its complete name and it indicates the other two using a wild-card character. A comma separates the two layer name text values.

4. At the Command: prompt, enter LOF and press the Enter key. The layers are turned off.

5. At the command prompt, enter LON and press the Enter key. The layers are turned on.

This is a simple, yet useful application of AutoLISP and script files. However, there is one occasion when the script file won't execute properly: when one of the layers you are trying to turn off is the current layer. AutoCAD expects you to respond by indicating that you really want to turn off the current layer. Because the script file does not address the response, AutoCAD halts execution of the script. The simplest way to avoid this problem is to set the EXPERT system variable to 1, which forces AutoCAD to simply turn off the current layer without asking if you really want to do so.


TIP: Setting the EXPERT system variable to 1 at the beginning of the script file is a good idea. Then set it back to 0 (its default value) at the end of the script file.

Performing Repetitive Tasks on Multiple Drawings

Script files are very useful for performing repetitive tasks on multiple drawings. For example, you can use the script file you created earlier for inserting the title block, add statements to open and save each drawing, and then use it to insert the title block into multiple sheets. The script can do this automatically by opening each drawing, inserting the block, saving the drawing, and then opening the next drawing.


TIP: I have used this feature frequently on large projects where hundreds of drawings were to have the same repetitive things done to them. By creating a script file that opened a file and executed several AutoLISP routines to edit the drawing, then using the script file to plot and save the drawing, I was able to perform hundreds of hours of work automatically. What's especially nice is that most of the work performed by the scripts was done overnight.

For a detailed example of how to quickly create large script files for plotting multiple sheets, see the section titled "Using Script Files for Multiple Plots," in Chapter 20, "Productive Plotting."

Using Slides

Just as new features are overshadowing the usefulness of script files, new software is overshadowing AutoCAD's slide show capability. Although AutoCAD's slide show capability is handy, other software is available that fulfills the same need and is easier to use and less expensive.

However, although AutoCAD may not be the easiest or cheapest software to use for running slide shows, if you already have AutoCAD and know how to use it, you might as well take advantage of what it can do.

Slide shows are simple to create. In fact, all you really need to read is AutoCAD's standard documentation. It does a good job of explaining how to create slide shows. Consequently, this section does not discuss using slides for slide shows.

Slides can also be used to make identifying AutoCAD commands easier. By inserting slides into an image tile menu, you create a graphical user interface where an AutoCAD command is executed by selecting a slide image in a tile, as discussed in the next section.

Creating Image Tile Menus

An image tile menu is a dialog box that enables you to execute a command or script file by selecting a tile. More importantly, the image tile menu is easily customized. The image tile menu dialog box displays 20 tiles, and each tile displays a single slide, as shown in figure 23.6. When you choose one of the slide images in a tile, AutoCAD executes the command associated with the tile.

The image tile menu shown in figure 23.6 is the Tiled Viewport Layout dialog box. You open it from View, Tiled Viewports, Layout. By choosing one of the tiles and clicking on OK, AutoCAD creates the tiled viewport arrangement shown in the image tile. The images in the tiles are slides that were made with the MSLIDE command. On the left side of the dialog box is a list of image tile names. Each name is associated with one tile, and a command is executed by selecting either the image tile or its name from the list.

Notice that not all of the tiles have a slide image. When you create an image tile menu to execute commands, it is not necessary to use all of the tiles. In figure 23.6, only 12 layouts are available. Consequently, the remaining unused image tiles are left blank. If selected, they execute no command, since no command is associated with them.

Creating image tile menus involves four basic steps:

Figure 23.6 The Tiled Viewport Layout image tile menu.

Probably the most useful purpose of image tile menus is for inserting blocks, which Chapter 12, "Creating and Using Blocks" briefly discusses. By creating a slide of a block and associating the slide with a tile in the image tile menu, you can quickly identify a block from a group of blocks. Then, the block can be inserted by selecting its image tile, which causes AutoCAD to execute the command associated with the tile. In this particular example, the INSERT command would be associated with the tile.

Through the next four exercises, you create an image tile menu that displays images of blocks and inserts a block when you select its associated image tile.

In the following exercise, you open a blank drawing and use it to create the slides for the image tile menu.


TIP: When you create the slides, you need to use your judgment to establish the image's appearance. Slides that you use in an image tile menu should fill up most of the tile's area. Also, the image should not be too complex. The complexity of an image becomes lost when you reduce its size to the point that you can place it on a tile.

Also, the tiles have a ratio of 1.5:1. They are 1.5 units wide by 1 unit tall. When you use the MSLIDE command to create a slide, AutoCAD uses the entire screen area. Unfortunately, your screen's ratio is probably not 1.5:1. Consequently, your slide may contain a lot of unwanted blank space. You can easily control the screen ratio by turning TILEMODE off and creating a viewport in paper space that is 1.5 units wide by 1 unit tall. Then edit your image inside the viewport in model space, and position it so the image fills the viewport. Once the image is properly positioned, create the slide.


CREATING SLIDES FOR AN IMAGE TILE MENU

1. Open the 23DWG05.DWG drawing file found on the accompanying CD.

2. Double-click on the TILE button on the status bar at the bottom of your screen. AutoCAD turns off TILE mode. You are now in paper space. Next, you create the viewport that you will use when making the slide images.

3. Choose View, Floating Viewports, 1 Viewport.

4. At the ON/OFF/Hideplot/Fit/2/3/4/Restore/<First Point>: prompt, enter 0,0.

5. Next, enter 1.5,0. AutoCAD creates a floating viewport that is the correct ratio for making slide images.

6. Choose View, Zoom, Extents.

The viewport fills the screen.

7. Double-click on the PAPER button in the status bar at the bottom of your screen.


Now you are ready to create the slides. You will create five slides, one for each sheet size.

8. Choose Insert, Block. The Insert dialog box displays.

9. Select the File button. The Select Drawing File dialog box displays.

10. Open the 23DWG05a.DWG drawing file found on the accompanying CD.

11. Click on the OK button to exit the Insert dialog box. When prompted, type 0,0 for the insertion point and accept the defaults for scale and rotation.

The 23DWG05a.DWG drawing contains the 8 1/2" * 11" sheet size. For purposes of this exercise, large text indicating the sheet size has been inserted. This makes identifying the sheet size in the image tile menu easier. After you create the image, you may edit the original drawing representing each block and erase the text.


Next, you size the image for use as a slide in the image tile menu.

12. Choose View, Zoom, Extents.

13. Choose View, Zoom, Scale.

14. At the Command: prompt, type 0.95X and press the Enter key. This provides a good size for the slide image, leaving a small white border around the edge of the image.


Next, you create the slide.

15. At the Command: prompt, type MSLIDE and press the Enter key. The Create Slide File dialog box opens.

16. Save the slide in the ACADR14\SUPPORT directory and name it 23DWG05a.SLD, the same name as the drawing file. In the File name text box, enter 23DWG05a.SLD, then choose Save. AutoCAD creates the slide.

17. Erase the inserted drawing. Then repeat steps 8 through 17 for the remaining drawings: 23DWG05b, 23DWG05c, 23DWG05d, and 23DWG05e.

Once the five slides are created, the next step is to combine them into a single file called a slide library.

To create a slide library from the slides, you use the SLIDELIB utility provided with AutoCAD and located in the ACADR14\SUPPORT directory. The utility compiles the slides into one file. To compile the slides, you pass a list of the slide file names to the utility.

A simple way to create the list of slide file names is to shell out of AutoCAD, change to the ACADR14\SUPPORT directory where the slides reside, and issue the DOS DIR command, using the syntax that automatically creates a .TXT file.


NOTE: The SLIDELIB utility creates a copy of the slides and stores them in a library file. Consequently, after you create the slide library, you can delete the original slide files. However, if you intend to add additional slides to the library file, you must re-create the file from scratch. You cannot simply add additional slides to an existing library file. Consequently, you must use all the original slide files to do so. It is a good idea, therefore, to save your original slide files.

The following exercise demonstrates how to create a slide library.

CREATING A SLIDE LIBRARY FROM SLIDES

1. At the Command: prompt, type SH and press the Enter key.

2. At the OS Command: prompt, press the Enter key.

The AutoCAD Shell Active window appears.

3. At the DOS prompt, type the following:

CD\
CD\ACADR14\SAMPLEWORK\NRP\R14\CHAP-23\DWG

This makes the ACADR14\SAMPLE directory current, which is where you saved the slide images from the last exercise. Next, you create the list of slide file names.

4. At the DOS prompt, type DIR *.SLD /b > SLDNAMES.TXT and press the Enter key.

The DIR command lists all files that end with SLD, one per line, and stores the results in an ASCII text file called SLDNAMES.TXT.


Next, you use the SLIDELIB utility to create the slide library file.

5. While still working from the AutoCAD shell Active window, type SLIDELIB SHEETS < SLDNAMES.TXT and press the Enter key.

AutoCAD executes the utility, and creates a slide library file named SHEETS.SLB. This is the file name you refer to when you define the image tile menu.

6. Type EXIT and press the Enter key. The AutoCAD Shell Active window closes.


After creating the slide library file, the next step is to modify the ACAD.MNU file and add the image tile menu commands.

The commands associated with each tile in the image tile menu are stored in the ACAD.MNU file. The ACAD.MNU file is an ASCII text file. You can edit it using most word processors. After you edit the file, be sure to save it as an ASCII text file.


TIP: When editing the ACAD.MNU file, it's a good idea to make a backup copy of it so that if something goes wrong during your editing session, you can recall the original menu file.

The following exercise demonstrates how to edit the ACAD.MNU file and add commands to the image tile menu area.


TIP: For this exercise, I use Windows WordPad to edit the menu file. Typically, I prefer to use Windows Notepad simply because I have used it for several years--it's my favorite text editor. Unfortunately, the typical ACAD.MNU file is too large to fit in Notepad.

ADDING IMAGE TILE MENU COMMANDS TO THE ACAD.MNU FILE

1. From the Start button on the Windows Taskbar, choose Programs, Accessories, WordPad.

2. Choose File, Open. The Open window appears.

3. In the File name text box, type *.MNU and press Enter. This forces the list box to display only file names that end with *.MNU.

You are searching for the ACAD.MNU file. It resides in AutoCAD's Support directory.

4. When you find the ACAD.MNU file, select the file to highlight the name and click on the Open button. The ACAD.MNU file is now ready for editing.


Next, you find the location to enter the image tile menu code.

5. Choose Edit, Find. The Find window opens.

6. In the Find what text box, type ***IMAGE, and then click on the Find Next button.

AutoCAD displays the ***IMAGE section. This represents the beginning of the image tile menu section. You enter new code at the end of this section.


Next, you enter the image tile menu code.

7. Click on Cancel to close the Find window.

8. Scroll down to display the ***IMAGE section, as shown in figure 23.7.

Figure 23.7 The ***IMAGE section of the ACAD.MNU file.

The last image tile menu entry is the section that starts with **image_vporti. Enter the new code following this section.

9. At the end of the ***IMAGE section, enter the following code:

**image_sheets
[Insert Sheet Block]
[sheets(23dwg05a,ANSI-A)]^C^C_.script 23scr05a.scr
[sheets(23dwg05b,ANSI-B)]^C^C_.script 23scr05b.scr
[sheets(23dwg05c,ANSI-C)]^C^C_.script 23scr05c.scr
[sheets(23dwg05d,ANSI-D)]^C^C_.script 23scr05d.scr
[sheets(23dwg05e,ANSI-E)]^C^C_.script 23scr05e.scr


This code tells AutoCAD the following:
**image_sheets indicates the beginning of a new image tile menu section.
[Insert Sheet Block] is the title that appears at the top of the Image Tile Menu dialog box.
The remaining code tells AutoCAD how to display the slides and what commands to execute when one of the image tiles is selected.
For example, the third line of code listed in the preceding tells AutoCAD to use the SHEETS.LIB file, display a slide named 23DWG05a, and to list the name ANSI-A in the text list at the left of the dialog box. Then, it instructs AutoCAD to cancel any active commands, and finally to execute the 23DWG05a.SCR script file.
The script files have already been created. When executed in AutoCAD, they create a new layer called BORDER, make it current, and then insert the appropriate block.

10. Save the ACAD.MNU file and close WordPad.


Next, you must reload into AutoCAD the ACAD.MNU file that you just edited.

11. At the Command: prompt, type MENU and press the Enter key. The Select Menu File dialog box opens.

12. From the Files of type drop-down list, select Menu Template (*.MNU). The ACAD.MNU file appears.

13. Select the ACAD.MNU file, then click on Open.

14. When AutoCAD issues the warning, choose Yes to overwrite the .MNS file. AutoCAD recompiles the new menu and loads it.


TIP: The warning AutoCAD issues notes that loading the MNU file overwrites the MNS file, which results in the loss of any toolbar customization changes. To avoid this, open and edit the MNS file instead of the MNU file.


The only step left is to create a simple AutoLISP routine to display the image tile menu.

Now that you have created the slide library and saved the commands in the ACAD.MNU file, you simply need to tell AutoCAD to open the new image tile menu you created. A simple way to do this is to define an AutoLISP routine.

The following exercise demonstrates how to create a simple AutoLISP routine to open an image tile menu.

OPENING AN IMAGE TILE MENU WITH AUTOLISP

1. At the Command: prompt, enter the following code:

(defun C:SHT (/) (menucmd "I=IMAGE_SHEETS") (menucmd "I=*"))

The preceding AutoLISP code uses the MENUCMD function to first load into memory the **IMAGE_SHEETS section you created, then displays the image tile menu.

2. At the Command: prompt, type SHT then press the Enter key.


The image tile menu appears, as shown in figure 23.8. To insert one of the blocks, choose it, and then choose OK. AutoCAD executes the appropriate script file, creates a new layer called BORDER and makes it current, and finally, inserts the block.

Figure 23.8 The new image tile menu.


By compiling slides in a slide library, you create a convenient way to store all your slides in one file. By using slides in image tile menus, you can create a graphical user interface that enables you to quickly identify commands and script files you want to execute.

Summary

This chapter discussed using script files and creating slide libraries. You have learned how to use script files to quickly set up your working environment. You discovered how to use script files to define and load AutoLISP routines, and how to load blocks into the block table without inserting the block into the drawing. This chapter showed you how to execute script files from simple AutoLISP commands. You also have learned about image tile menus, and how to create properly scaled slides for them. You found out how to compile those slides in a slide library file. You also learned how to edit the ACAD.MNU file for use with image tile menus, and how to start a script file from an image tile menu.

By using the techniques discussed in this chapter, you can easily create simple programs with script files that can automatically perform repetitive tasks. By using image tile menus, you can quickly identify a script file graphically and start it. The examples you have seen demonstrate how you can perform repetitious tasks quickly and accurately, to increase your productivity.


Previous chapterNext chapterContents

© Copyright, Macmillan Computer Publishing. All rights reserved.